package com.kejiguan.ui.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * Created by YYY on 16/8/19.
 */
public class KjgEditText extends EditText{


    private Paint backgroundPaint;
    private int backgroundPaintColor=0x4C99F1FF;
    private RectF startOval,endOval;

    public KjgEditText(Context context) {
        super(context);
        init(context);
    }

    public KjgEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public KjgEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public KjgEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {

        backgroundPaint=new Paint();
        backgroundPaint.setColor(backgroundPaintColor);
        backgroundPaint.setAntiAlias(true);
        backgroundPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    public void  onSizeChanged(int w, int h, int oldw, int oldh)
    {
        super.onSizeChanged(w,h,oldw,oldh);

        startOval=new RectF(0,0,getHeight(),getHeight());
        endOval=new RectF(getWidth()-getHeight(),0,getWidth(),getHeight());
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        canvas.drawArc(startOval,90,180,true,backgroundPaint);
        canvas.drawArc(endOval,270,180,true,backgroundPaint);
        canvas.drawRect(getHeight()/2+1,0,getWidth()-getHeight()/2-1,getHeight(),backgroundPaint);
        super.onDraw(canvas);
    }
}
